package cn.edu.hunau.pm.common;

import java.util.HashMap;
import java.util.Map;

//封装响应的结果
public class R {
    private Boolean flag;//标识结果的状态，成功为true
    private String message;//状态的描述
    private Integer code;//业务状态码
    private Map<String,Object> data;//响应的结果
    public R() {

    }
    public R(Boolean flag,String message,Integer code) {
        this.flag = flag;
        this.code=code;
        this.message=message;
        this.data=new HashMap<>();

    }

    public Boolean getFlag() {
        return flag;
    }

    public void setFlag(Boolean flag) {
        this.flag = flag;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }


    public static R error()
    {
        R r = new R();
        r.setFlag(false);
        return r;
    }
    public R code(Integer code)
    {
        this.setCode(code);
        return this;
    }
    public R message(String message)
    {
        this.setMessage(message);
        return this;
    }

    public static R ok()
    {
        R ok=new R(true,"ok",200200);

        return ok;
    }
    public R data(String key,Object value)
    {
        this.data.put(key,value);

        return this;
    }
}
